//
//  DigitNoteInfoViewController.m
//  NewApp
//
//  Created by  on 12-7-8.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "DigitNoteInfoViewController.h"
#import "DigitNoteSearchResultViewController.h"

@interface DigitNoteInfoViewController ()

@end

@implementation DigitNoteInfoViewController

#pragma mark -
#pragma mark - Views lifecycle and memory management

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _searchBar = [[NASearchBar alloc] initWithFrame:CGRectMake(0.f, 25.f, 320.f, 44.f)];
    _searchBar.delegate = self;
    [self.view addSubview:_searchBar];
    
    self.scrollView.frame = CGRectMake(0.f, 69.f, 320.f, 460.f - 25.f - 49.f - 44.f - 44.f);
}

- (void) dealloc {
    [_searchBar release];
    [super dealloc];
}

#pragma mark -
#pragma mark - Override methods

- (void) loadInlineInfos {
    [self.engine productInfosWithID:self.ID];
}

- (void) requestDidFinished:(RequestEngine *)reqEngine withObject:(id)object {
    [super requestDidFinished:reqEngine withObject:object];
    
    if ([object isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dic = (NSDictionary *) object;
        [dic retain];
        
        NSArray *objects = [dic objectForKey:@"data"];
        if (objects.count > 0) {
            NSDictionary *dataDic = [[dic objectForKey:@"data"] objectAtIndex:0];
            if (dataDic != nil) {
                
                //Retrieve text
                NSString *itemName = [dataDic objectForKey:kItemName];
                if (itemName != nil && itemName.length > 0) { 
                    [self.imageView setImageDescription:itemName];
                }
        }

        [dic release];

        }
    }

}

#pragma mark -
#pragma mark - NASearchBarDelegate methods

- (void) searchButtonDidPressed {
    if (_searchBar.keywordTextfield.text.length == 0) 
        return;
    self.title = @"返回";
    DigitNoteSearchResultViewController *viewCtrl = [[DigitNoteSearchResultViewController alloc] initWithID:nil keyword:_searchBar.keywordTextfield.text];
    [self.navigationController pushViewController:viewCtrl animated:YES];
    [viewCtrl release];
    
}


@end
